/***************************************************************************
 *   Copyright (C) 2008 by BogDan Vatra                                    *
 *   bogdan@licentia.eu                                                    *
 *                                                                         *
 *   This program is free software: you can redistribute it and/or modify  *
 *   it under the terms of the GNU General Public License as published by  *
 *   the Free Software Foundation, either version 3 of the License, or     *
 *   (at your option) any later version.                                   *
 *   This program is distributed in the hope that it will be useful,       *
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
 *   GNU General Public License for more details.                          *
 *   You should have received a copy of the GNU General Public License     *
 *   along with this program.  If not, see <http://www.gnu.org/licenses/>. *
 ***************************************************************************/
#ifndef TABLEVIEW_H
#define TABLEVIEW_H

#include <QTableView>
#include "win32def.h"

/**
	@author BogDan Vatra <taipan@omnidatagrup.ro>
*/

class KONTAMABIL_EXPORTS TableView : public QTableView
{
	Q_OBJECT
	Q_PROPERTY(QString queryName READ queryName WRITE setQueryName)
	Q_PROPERTY(QStringList fields READ fields WRITE setFields)
	Q_PROPERTY(QStringList heads READ heads WRITE setHeads)
	Q_PROPERTY(QString checkableField READ checkableField WRITE setCheckableField)
	Q_PROPERTY(QString keyField READ keyField WRITE setKeyField)

public:
	TableView(QWidget *parent = 0);

	const QString & queryName();
	void setQueryName(const QString & queryName);

	const QStringList & fields();
	void setFields(QStringList & fields);

	const QStringList & heads();
	void setHeads(QStringList heads);

	QString checkableField();
	void setCheckableField(const QString & checkableField);
	QString keyField();
	void setKeyField(const QString &keyField);

	Q_INVOKABLE QString arrayOfCheckedFileds();
	Q_INVOKABLE QString nameOfCheckedFileds();

public slots:
	void checkAll();
	void unckeckAll();

signals:
	void returnPressed();
	void escapePressed();
	void insertPressed();
	void deletePressed();
	void focusIn();
	void focusOut();

protected:
	void keyPressEvent(QKeyEvent * event);
	void showEvent ( QShowEvent * event );
	void hideEvent ( QHideEvent * event );
	void focusInEvent(QFocusEvent * event);
	void focusOutEvent(QFocusEvent * event);

	QString uniqueName();

private slots:
	void before();
	void after();

private:
	QString m_queryName;
	QString m_checkableField;
	QString m_keyField;
	QStringList m_fields, m_heads;

};

#endif
